package com.sdy.hospitalguard.web.websocket;

import com.sdy.hospitalguard.biz.event.WebsocketEvent;
import com.sdy.mq.base.BaseMessageConsumer;
import com.sdy.mvc.utils.JsonUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.common.message.MessageExt;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Component;

/**
 * <p>
 * 消费
 * </p>
 *
 * @author fb
 * @since 2020/5/8
 */
@Slf4j
@Component
public class WebsocketEventConsumer extends BaseMessageConsumer {
    @Autowired
    private ApplicationContext applicationContext;

    @Override
    protected boolean consume(MessageExt message) {
        try {
            WebsocketEvent websocketEvent = JsonUtil.deserialize(message.getBody(), WebsocketEvent.class);
            applicationContext.publishEvent(websocketEvent);
        } catch (Exception e) {
            log.error("", e);
        }
        return true;
    }
}
